package net.ba.models
{
	
	import flash.utils.Dictionary;
	
	public class CellArray
	{
		public var cells:Dictionary = new Dictionary();
		public var totalOcc:int =0;
		public var totalCells:int=0;
		
		public function CellArray()
		{
			cells = new Dictionary();		
		}
		
		public function getCellCount(cellId:Number):int {
			return cells[cellId];
		}
		
		public function sumCell(cellId:int, count:int):void {
			if (count >0) {
				if (!cells[cellId]) {
					totalCells ++;
				}
				sumToCell(cellId,count);
				totalOcc +=count;	
				
			}
		}
		
		private function sumToCell(cellId:Number,count:int):void {
			if (cells[cellId]) {
				cells[cellId] += count;
			} else {
				cells[cellId] = count;
			}
		}
		
		public function regenerateArray():void {
	  		cells = new Dictionary();
		  	totalCells = 0;	 
		  	totalOcc = 0; 		
	  		
		}
		
		public function updateCell(cellId:int, count:int):void {
			
			if (!cells[cellId] && count>0) {
				totalCells ++;
				totalOcc +=count;
			}			
			if (count == 0 && cells[cellId]) {
				totalCells --;
				totalOcc = totalOcc - cells[cellId];
			}
			
			cells[cellId] = count;
		}
		


	}
}